/***********************************************************
 * Ports:    
 *  VL_IN8(&rstn,0,0);
 *  VL_IN8(&sys_clk,0,0);
 *  VL_IN8(&set_time,0,0);
 *  VL_IN8(&set_hour,0,0);
 *  VL_IN8(&set_min,0,0);
 *  VL_IN8(&set_alarm,0,0);
 *  VL_IN8(&toggle,0,0);
 *  VL_OUT8(&beep,0,0);
 *  VL_OUT16(&hour,15,0);
 *  VL_OUT16(&min,15,0);
 *  VL_OUT16(&sec,15,0);
************************************************************/

#include "clock.h"

#define PERIOD 2
#define MAX_TIME 88000*PERIOD

uint64_t sim_time = 0;

int main() {
  Clock clock;

	Verilated::traceEverOn(true);
	VerilatedVcdC *m_trace = new VerilatedVcdC;
	clock.dut->trace(m_trace, 2);
	m_trace->open("waveform.vcd");

  while(sim_time < 100) {
    if(sim_time < uint(1.5*PERIOD)) {
      clock.reset_clock();
    } else {
      clock.dereset_clock();
    }
    
    // set alarm
    if(sim_time > uint(1.5*PERIOD) && sim_time <= 32*PERIOD) {
      clock.set_alarm_hour(1);
      clock.set_alarm_min(1);
    } else {
      clock.set_alarm_hour(0);
      clock.set_alarm_min(0);
    }

    if(sim_time == 87000*PERIOD) {
      std::cout << "\n\n\nNow test set time.\n\n" << std::endl;
    }

    // if(sim_time > 87000*PERIOD && sim_time < 87100*PERIOD) {
    //   clock.set_time_hour(1);
    //   clock.set_time_min(1);
    // } else {
    //   clock.set_time_hour(0);
    //   clock.set_time_min(0);
    // }

    if(sim_time < 87100*PERIOD && sim_time % 2 == 0) {
      clock.show_clock();
      clock.show_alarm();
    }

    if(sim_time % PERIOD == 0) {
	  	clock.pos_edge();
	  	m_trace->dump(sim_time);
	  	clock.neg_edge();
	  }

    if((sim_time % PERIOD) - 1 == 0) {
      clock.neg_edge();
      m_trace->dump(sim_time);
      clock.pos_edge();
    }

	  sim_time++;
  }

  clock.dut->final();

  m_trace->close();
}

